<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head th:replace="_fragments :: head(~{::title})">
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>博客管理</title>
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/semantic-ui/2.2.10/semantic.min.css">
    <link rel="stylesheet" href="../../static/css/me.css" th:href="@{css/me.css}"> <!--引入自定义CSS样式-->
</head>
<body>
    <!--导航-->
    <nav th:replace="admin/_fragments :: menu(1)" class="ui inverted attached segment me-padded-tb-mini me-shadow-small"> <!--引入css样式-->
        <div class="ui container">
            <div class="ui inverted secondary menu stackable"><!--stackable可堆叠，解决手机访问-->
                <h2 class="ui teal header item">后台管理</h2> <!--item为menu中的一个条目-->
                <a href="#" class="active m-item item me-mobile-hide"><i class="home icon"></i>博客</a><!--href为超链接-->
                <a href="#" class="m-item item me-mobile-hide"><i class="idea icon"></i>分类</a><!--m-item，在JQuery里获取样式-->
                <a href="#" class="m-item item me-mobile-hide"><i class="tags icon"></i>标签</a>

                <div class="right m-item me-mobile-hide menu">
                    <div class="ui dropdown item">
                        <div class="text">
                            <img src="../../static/images/wechat.jpg" alt="" class="ui avatar image">
                            泽宝宝
                        </div>
                        <i class="dropdown icon"></i>
                        <div class="menu">
                            <a href="#" class="item">注销</a>
                        </div>
                    </div>
                </div>
            </div>
        </div>
        <a href="#" class="ui black icon button me-top-right me-mobile-show menu toggle"> <!--手机端菜单图标, menu toggle获取点击事件-->            <i class="sidebar icon"></i>
        </a>
    </nav>

    <!--二级导航-->
    <div class="ui attached pointing menu"> <!--active的就可以有小箭头-->
        <div class="ui container">
            <div class="right menu">
                <a href="#" target="_blank" th:href="@{/admin/blogs/input}" class="item">发布</a>
                <a href="#" th:href="@{/admin/blogs}" class="teal active item">列表</a>
            </div>

        </div>
    </div>

    <!--中间内容-->
    <div class="me-container-medium me-padded-tb-large">
        <div class="container">
            <!--查询等的表单-->
            <div style="text-align: center" method="post" class="ui secondary segment stackable form"> <!--表单-->
                    <input type="hidden" name="page"><!--定义隐含域？？？？-->
                    <div class="inline fields"> <!--inline 不充满整行-->
                        <!--标题-->
                        <div class="field">
                            <input id="title-search" style="min-width: 215px" type="text" name="title" placeholder="标题">
                        </div>
                        <!--类型下拉框-->
                        <div class="field">
                            <div id="typeMenu" style="min-width: 215px" class="ui selection dropdown"><!--选择式下拉框-->
                                <input type="hidden" name="typeId">
                                <i class="dropdown icon"></i>
                                <div class="default text">分类</div>
                                <div class="menu">
                                    <div th:each="type: ${types}" class="item" data-value="1"
                                         th:data-value="${type.id}" th:text="${type.name}">错误日志</div><!--data-value为传到后端的值-->
                                </div>
                            </div>
                        </div>

                        <!--标签下拉框-->
                        <div class="field">
                            <div id="tagMenu" style="min-width: 215px" class="ui selection dropdown"><!--选择式下拉框-->
                                <input type="hidden" name="tagId">
                                <i class="dropdown icon"></i>
                                <div class="default text">标签</div>
                                <div class="menu">
                                    <!--为什么不用th:value? -->
                                    <div th:each="tag: ${tags}" class="item" data-value="1"
                                         th:data-value="${tag.id}" th:text="${tag.name}">错误日志</div><!--data-value为传到后端的值-->
                                </div>
                            </div>
                        </div>
                        <!--recommend checkbox-->
                        <!--<div class="field">
                            <input type="checkbox" id="enableRecommend" name="enableRecommend">
                            <label for="enableRecommend">推荐</label>
                        </div>

                        <div class="field">
                            <input type="checkbox" id="published" name="published">
                            <label for="published">发布</label>
                        </div>-->
                        <!--search button-->
                        <div class="field">
                            <button type="button" id="search-btn" class="ui mini teal basic button"><i class="search icon"></i>搜索</button>
                        </div>
                        <div class="field">
                            <button type="button" id="clear-btn" class="ui mini teal basic button">清空</button>
                        </div>
                    </div>
                </div>

            <!--表格-->
            <div id="table-container"> <!--通过jQuery获取-->
                <!--返回到这里，其他地方不会加载-->
                <table th:fragment="blogList" class="ui teal celled compact table"><!--celled加网格-->
                    <thead>
                    <tr>
                        <th></th>
                        <th>标题</th>
                        <th>类型</th>
                        <th>是否推荐</th>
                        <th>是否发布</th>
                        <th>更新时间</th>
                        <th>操作</th>
                    </tr>
                    </thead>
                    <tbody>
                    <tr th:each="blog, iterStat : ${page.content}">
                        <td th:text="${iterStat.count}">1</td>
                        <td th:text="${blog.title}">联系清单</td>
                        <td th:text="${blog.type.name}">认知升级</td>
                        <td th:text="${blog.enableRecommend ? '是' : '否'}"></td>
                        <td th:text="${blog.published ? '发布' : '草稿'}"></td>
                        <td th:text="${blog.updateTime}">2020-02-20 21：34</td>
                        <td>
                            <a th:href="@{/admin/blogs/{id}/input(id=${blog.id})}" href="#" target="_blank" class="ui basic mini button teal">编辑</a>
                            <a th:href="@{/blog/{id}(id=${blog.id})}" href="#" target="_blank" class="ui basic mini button blue">详情</a>
                            <a th:href="@{/admin/blogs/{id}/delete(id=${blog.id})}" href="#" onclick="return del();" class="ui basic mini button red">删除</a>
                        </td>
                    </tr>
                    </tbody>
                    <tfoot><!--表底部-->
                    <tr>
                        <th colspan="7"><!--合并单元格-->
                            <div class="ui two column grid">
                                <div class="column">
                                    <div class="ui mini pagination menu" th:if="${page.totalPages>1}"><!--分页菜单-->
                                        <a onclick="page(this)" th:attr="data-page=${page.number}-1" th:unless="${page.first}" href="#" class="item">上一页</a>
                                        <a onclick="page(this)" th:attr="data-page=${page.number}+1" th:unless="${page.last}" href="#" class="item">下一页</a>
                                    </div>
                                </div>
                                <div class="middle aligned column">
                                    <a href="#" th:href="@{/admin/blogs/input}" target="_blank" class="ui mini middle aligned right floated teal basic button">新增</a>
                                </div>
                            </div>
                        </th>
                    </tr>
                    </tfoot>
                </table>

                <div class="ui success message" th:unless="${#strings.isEmpty(message)}">
                    <i class="close icon"></i>
                    <div class="header">提示：</div>
                    <p th:text="${message}">恭喜，操作成功！</p>
                </div>
            </div>
        </div>
    </div>

    <!--底部footer-->
    <footer th:replace="admin/_fragments :: footer" class="ui inverted vertical segment me-padded-tb-max"><!--vertical消除圆角，用attached好像也行-->
        <div class="ui center aligned container"><!--居中-->
            <div class="ui inverted divided grid stackable"><!--grid stackable默认均匀分成16份, divided分割线-->
                <div class="three wide column">
                    <div class="ui inverted link list">
                        <div class="item">
                            <img src="../../static/images/wechat.jpg" class="ui rounded image" alt="" style="width: 110px"><!--alt规定图片无法显示时的替代文本-->
                        </div>
                    </div>
                </div>
                <div class="three wide column">
                    <h4 class="ui inverted header me-text-space me-opacity-mini">最新博客</h4><!--标题-->
                    <div class="ui inverted link list">
                        <a href="#" class="item me-text-thin me-text-lined">用户故事</a>
                        <a href="#" class="item me-text-thin me-text-lined">用户故事</a>
                        <a href="#" class="item me-text-thin me-text-lined">用户故事</a>
                    </div>
                </div>
                <div class="three wide column">
                    <h4 class="ui inverted header me-text-space me-opacity-mini">联系我</h4><!--标题-->
                    <div class="ui inverted link list">
                        <a href="#" class="item me-text-thin me-text-lined">Email: stg1205@163.com</a>
                        <a href="#" class="item me-text-thin me-text-lined">QQ: 1014922487</a>
                    </div>
                </div>
                <div class="seven wide column">
                    <h4 class="ui inverted header me-text-space me-opacity-mini">介绍</h4>
                    <p class="me-text-space me-text-thin me-text-lined me-opacity-mini">这是我的个人博客，啦啦啦啦啦啦拉拉拉啊拉啦阿拉</p>
                </div>
            </div>
            <div class="ui inverted section divider"></div>
            <p class="me-text-space me-opacity-tiny">Copyright</p>
        </div>

    </footer>
    <th:block th:replace="_fragments :: script"></th:block>

    <script>
        // 删除确认框
        function del() {
            var msg = "确认删除博客？";
            if (confirm(msg) === true) {
                return true;
            } else {
                return false;
            }
        }

        $('.menu.toggle').click(function () {
            $('.m-item').toggleClass('me-mobile-hide');/*toggleClass，取反函数*/
        });

        $('.ui.dropdown').dropdown({
            on: 'hover' /*鼠标放上就触发*/
        });

        function page(obj) { //定义page方法获取name为page的隐含域对应的值
            $("[name='page']").val($(obj).data("page"));
            loadData();
        }

        $("#search-btn").click(function () {
            $("[name='page']").val(0);
            loadData();
        });

        $('#clear-btn').click(function () {
            $('#title-search').val(null);
            $('#typeMenu').dropdown("clear");
            $('#tagMenu').dropdown("clear");
        });

        function loadData() {
            $("#table-container").load(/*[[@{/admin/blogs/search}]]*/"/admin/blogs/search", {
                title: $("[name='title']").val(),
                typeId: $("[name='typeId']").val(),
                tagId: $("[name='tagId']").val(),
                enableRecommend: $("[name='enableRecommend']").prop('checked'),
                published: $("[name='published']").prop('checked'),
                page: $("[name='page']").val()
            });
        }

        /*使message组件具有可关闭的功能*/
        $(' .message .close').on( //需要空格？？？
            'click', function () {
                $(this).closest('.message').transition('fade');
            }
        );

        //要加后面的""里的地址
        $('#newBlog-container').load(/*[[@{/footer/newBlogs}]]*/"/footer/newBlogs");
    </script>
</body>
</html>